package com.example.demo.model;

import com.example.demo.entity.ProductSupplier;
import com.example.demo.mapper.SupplierMapper;
import com.example.demo.request.Supplier.ListRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;
@Repository
public class SupplierModel extends Model {

    @Autowired
    SupplierMapper supplierMapper;
    public Map<String, Object> getList(ListRequest listRequest) {
        int[] page = this.getPage(listRequest.page_size,listRequest.page_no);
        String like_company_name = this.whereLike(listRequest.company_name);
        String like_supplier_name = this.whereLike(listRequest.supplier_name);
        List<ProductSupplier> ProductSuppliers = supplierMapper.list(like_company_name,like_supplier_name,listRequest.status,page[0],page[1]);
        return this.toPage(ProductSuppliers,listRequest);
    }

    public ProductSupplier detail(int id) {
        ProductSupplier ProductSupplier =  supplierMapper.getSupplierById(id);
        return ProductSupplier;
    }
}
